# -*- coding: iso-8859-1 -*- import socket class _Getch: def __init__(self): try: self.impl = _GetchWindows() except ImportError: self.impl = _GetchUnix() def __call__(self): return self.impl() class _GetchUnix: def __init__(self): import tty, sys def __call__(self): import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd,termios.TCSADRAIN,old_settings) return ch class _GetchWindows: def __init__(self): import msvcrt def __call__(self): import msvcrt return msvcrt.getch() getch = _Getch() s = socket.socket() # Create a socket object host = '10.1.32.180' # Get local machine name port = 50123 # Reserve a port for your service. s.connect((host, port)) char = getch() while char != 'q': s.send(char) char = getch()